﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>SoundGet - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The SoundGet function retrieves various settings from a sound device (master mute, master volume, etc.)" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>SoundGet</h1>

<p>Retrieves various settings from a sound device (master mute, master volume, etc.)</p>

<pre class="Syntax">Setting := <span class="func">SoundGet</span>(<span class="optional">ComponentType, ControlType, DeviceNumber</span>)</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>ComponentType</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>If omitted or blank, it defaults to the word MASTER. Otherwise, it can be one of the following words: MASTER (synonymous with  SPEAKERS), DIGITAL, LINE, MICROPHONE, SYNTH, CD, TELEPHONE, PCSPEAKER, WAVE, AUX, ANALOG, HEADPHONES, or N/A. If the sound device lacks the specified <em>ComponentType</em>, ErrorLevel will indicate the problem.</p>
    <p>The component labeled Auxiliary in some mixers might be accessible as ANALOG rather than AUX.</p>
    <p>If a device has more than one instance of <em>ComponentType</em> (two of type LINE, for example), usually the first contains the playback settings and the second contains the recording settings. To access an instance other than the first, append a colon and a number to this parameter. 例如: <code>Analog:2</code> is the second instance of the analog component.</p>
  </dd>

  <dt>ControlType</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>If omitted or blank, it defaults to VOLUME. Otherwise, it can be one of the following words: VOLUME (or VOL), ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, BASSBOOST, PAN, QSOUNDPAN, BASS, TREBLE, EQUALIZER, or the number of a valid control type (see <a href="SoundSet.htm#ExSoundcard">soundcard analysis script</a>). If the specified <em>ComponentType</em> lacks the specified <em>ControlType</em>, ErrorLevel will indicate the problem.</p>
    <p class="note"><strong>Note:</strong> Sound devices usually support only VOLUME (or VOL) and MUTE, although others may be available depending on Windows and the sound device.</p>
  </dd>

  <dt>DeviceNumber</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>A number between 1 and the total number of supported devices. If this parameter is omitted, it defaults to the system's default device for playback. The <a href="SoundSet.htm#ExSoundcard">soundcard analysis script</a> may help determine which number to use.</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>Type: <a href="../Concepts.htm#numbers">Float</a>, <a href="../Concepts.htm#boolean">Integer (boolean)</a> or <a href="../Concepts.htm#nothing">String (empty)</a></p>
<p>For <em>ControlType</em>s ONOFF, MUTE, MONO, LOUDNESS, STEREOENH and BASSBOOST, the return value is the <a href="../Concepts.htm#numbers">integer</a> 1 (meaning ON) or 0 (meaning OFF). For all other <em>ControlType</em>s, the return value is a <a href="../Concepts.htm#numbers">floating-point number</a> between 0 and 100 (inclusive). If the setting cannot be retrieved, an empty string is returned.</p>

<h2>ErrorLevel</h2>
<p>如果函数成功, <a href="../misc/ErrorLevel.htm">ErrorLevel</a> 设置为 0. 否则, 它被设置为以下短语之一:</p>
<ul>
    <li>Invalid Control Type or Component Type</li>
    <li>Can't Open Specified Mixer</li>
    <li>Mixer Doesn't Support This Component Type</li>
    <li>Mixer Doesn't Have That Many of That Component Type</li>
    <li>Component Doesn't Support This Control Type</li>
    <li>Can't Get Current Setting</li>
</ul>
<h2 id="Remarks">备注</h2>
<p>To discover the capabilities of the sound devices (mixers) installed on the system -- such as the available component types and control types -- run the <a href="SoundSet.htm#ExSoundcard">soundcard analysis script</a>.</p>
<p>For more functionality and finer grained control over audio, consider using the <a href="https://www.autohotkey.com/board/topic/21984-vista-audio-control-functions/">VA library</a>.</p>
<p>Use <a href="SoundSet.htm">SoundSet</a> to change a setting.</p>
<h2 id="Related">相关</h2>
<p><a href="SoundSet.htm">SoundSet</a>, <a href="SoundPlay.htm">SoundPlay</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>master_volume := SoundGet()
MsgBox "Master volume is " master_volume " percent."

master_mute := SoundGet(, "Mute")
MsgBox "Master Mute is currently " master_mute "."

bass_level := SoundGet("Master", "Bass")
if ErrorLevel
    MsgBox "Error Description: " ErrorLevel
else
    MsgBox "The BASS level for MASTER is " bass_level " percent."

microphone_mute := SoundGet("Microphone", "Mute")
if microphone_mute = "Off"
    MsgBox "The microphone is not muted."</pre>
</div>

</body>
</html>